package com.cjjd.c.feature.mine.message;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.ActionBarFragment;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.SysMessageDetailBean;
import com.cjjd.c.bean.SysMessageModel;
import com.cjjd.c.http.CallbackImpl;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.SharePrefUtil;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by dadagm on 17/9/18.
 */

public class SystemMessageDetailFragment extends ActionBarFragment {

    String id;
    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.time)
    TextView time;
    @Bind(R.id.message)
    TextView message;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        id = getArguments().getString("id");

        donet();
    }

    private void donet(){
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId));
        h1.put("uuid", id);

        service.getSysMessageDetail(JsonUtils.convertParam("getSysMessageDetail", h1)).enqueue(new CallbackImpl<SysMessageDetailBean>() {

            @Override
            public void responseSuccess(Call<HttpResult<SysMessageDetailBean>> call, Response<HttpResult<SysMessageDetailBean>> response) {

                SysMessageModel bean=response.body().data.sysMessage;
                title.setText(bean.messageHeader);
                time.setText(Html.fromHtml("系统发布于"+bean.enterTime));
                message.setText(Html.fromHtml(bean.messageCenter));

            }
        });


    }

    @Override
    public Object getTitleString() {
        return "系统消息详情";
    }

    @Override
    public int getContentView() {
        return R.layout.fragment_marketingnotice;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
